<?php

$original = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];

function pc_array_power_set($arr)
{
    $results = [[]];
    foreach ($arr as $elem) {
        foreach ($results as $combination) {
            array_push($results, array_merge([$elem], $combination));
        }
    }
    return $results;
}
$s = microtime(true);
$r = pc_array_power_set($original);
echo 'size: ' . count($r) . PHP_EOL;
echo 1000 * (10000 * microtime(true) - 10000 * $s) / 10000 . ' ms' . PHP_EOL;

function pc_array_power_set1($array, $limit){
    $subset = [];
    $results = [[]];
    foreach ($array as $element){
        foreach ($results as $combination){
            $result = array_merge([$element], $combination);
            array_push($results, $result);
            if(count($result) >= $limit){
                $subset[] = $result;
            }
        }
    }
    return $subset;
}
$s = microtime(true);
$r = pc_array_power_set1($original, 2);
echo 'size: ' . count($r) . PHP_EOL;
echo 1000 * (10000 * microtime(true) - 10000 * $s) / 10000 . ' ms' . PHP_EOL;
